<?php get_header(); ?>
<?php setPostViews(get_the_ID());?>
<div id="postlist">
	<?php if(have_posts()): ?>
			<?php while(have_posts()):the_post(); ?>
				<div class="post">
					<div class="posttitle"><h2><?php the_title(); ?></h2></div>
					<div class="clear"></div>
					<div class="postinfo">
							<?php _e('Author','may701'); ?><?php the_author_posts_link(); ?>&nbsp;&nbsp;&nbsp;&nbsp;
							<?php _e('Category','may701');?><?php the_category(', ');?>&nbsp;&nbsp;&nbsp;&nbsp;
							<?php _e('view','may701');?><?php echo getPostViews(get_the_ID());?><?php _e('numbers','may701')?>&nbsp;&nbsp;&nbsp;&nbsp;
							<?php _e('time','may701');?><?php the_time('Y-m-d h:m'); ?>
							<?php edit_post_link('Edit', ' | ', ''); ?>
					</div>
					<div class="entry">
						<?php the_content(); ?>
					</div>
				</div>
				<div class="comfrm">
					<div class="comcon">
						<?php comments_template('', true ); ?>	
					<br/>
					</div>
				</div>
				<?php  
					$comcount=get_comment_count(get_the_ID());
					if($comcount['approved']==0)
					{ ?>
				<script type="text/javascript">
					$(window).load(function(){
						$postHeight=$(".post").height();
						$comHeight=$(".comfrm").height();
						$(window).scroll(function(){
							if($.browser.safari)
							{
							   $top=$("body")[0].scrollTop;
							}
							else
							{
								$top=$("html")[0].scrollTop;
							}
							if($top>120)
							{
								$martop=$top-70;
								if($martop<$postHeight-$comHeight)
								{
									$bodyw=$(window).width();
									if($bodyw>1000)
									{
										$right=($bodyw-1000)/2+1;
										$right+="px"
										$(".comfrm").css({"position":"fixed","top":"40px","right":$right});
									}
								}
								else
								{
									$(".comfrm").css({"position":"static"});
								}
							}
							else
							{
								$(".comfrm").css({"position":"static"});
							}
						});
					});
				</script>
				<?php } else { ?>
				<script type="text/javascript">
					$(window).load(function(){
						$postHeight=$(".post").height();
						if($postHeight<800)
						{
							$(".comfrm").css({height:"800px",overflow:"scroll","overflow-x":"hidden"});
						}
						else
						{
							$(".comfrm").css({height:$postHeight,overflow:"scroll","overflow-x":"hidden"});
						}
					});
				</script>
				<?php } ?>
			<?php endwhile; ?>
	<?php else: ?>
			<div class="post">
				<h2><?php _e('sorry,no posts','may701'); ?></h2>
			</div>
	<?php endif; ?>	

	<!--related posts-->
	<div class="clear"></div>
	<div id="relposts">
		<div class="post-rel-new">
			<h2><?php _e('newest posts','may701')?></h2>
			<?php my_get_posts( $orderby='date', $plusmsg ='post_date');?>
		</div>
		<div class="post-rel-new">
			<h2><?php _e('hot posts','may701')?></h2>
			<?php my_get_posts( $orderby = 'comment_count', $plusmsg = 'post_date');?>
		</div>
		<div class="post-rel-new">
			<h2><?php _e('random posts','may701')?></h2>
			<?php my_get_posts($orderby = 'rand', $plusmsg = 'post_date' );?>
		</div>
	</div>
</div>
<?php get_footer(); ?>
